﻿
Imports std
Imports storoomc
Imports storcore

Public Class nodes_redundance3
    Inherits nodes_redundance2

    Private Shared Function c(ByVal si As storageInterface) As storoomTalk
        Return convertor.cast(Of storoomTalk)(si)
    End Function

    Protected Overrides Function _storageInterfaceReadImpl(ByVal si As storageInterface, ByVal key As String, _
                                                           ByRef buff As bytes, ByRef ts As Int64) As Boolean
        Return c(si).tsRead(key, buff, ts)
    End Function

    Protected Overrides Function _storageInterfaceWriteImpl(ByVal si As storageInterface, ByVal key As String, _
                                                            ByVal buff As bytes, ByVal ts As Int64) As Boolean
        Return c(si).tsWrite(key, buff, ts)
    End Function

    Protected Overrides Function _storageInterfaceModifyImpl(ByVal si As storageInterface, ByVal key As String, _
                                                             ByVal buff As bytes, ByVal ts As Int64) As Boolean
        Return c(si).tsModify(key, buff, ts)
    End Function

    Protected Overrides Function seekwork(ByVal slice As storageInterface, ByRef key As String) As Boolean
        Return c(slice).tsSeek(key)
    End Function

    Protected Overrides Function listwork(ByVal slice As storageInterface, ByRef arg As vector(Of String)) As Boolean
        Return c(slice).tsList(arg)
    End Function

    Private Class deleteInfo
        Inherits storoomDistrTM.deleteInfo

        Protected Overrides Function operationImpl() As ternary
            Return ifoper(c(slice).tsDelete(key), ternary.true, ternary.false)
        End Function

        Public Shared Shadows Function createInfo() As deleteInfo
            Return New deleteInfo()
        End Function
    End Class

    Protected Overrides Function deleteImpl(ByVal key As String, ByVal slices As vector(Of storageInterface)) As Boolean
        Return deleteImpl(key, slices, AddressOf deleteInfo.createInfo)
    End Function

    Private Shadows Class sizeofInfo
        Inherits nodes_redundance2.sizeofInfo

        Protected Overrides Function operationImpl() As ternary
            Return ifoper(c(slice).tsSizeof(key, size), ternary.true, ternary.false)
        End Function

        Public Shared Shadows Function createInfo() As sizeofInfo
            Return New sizeofInfo()
        End Function
    End Class

    Protected Overrides Function sizeofImpl(ByVal key As String, ByRef size As UInt64, _
                                            ByVal slices As vector(Of storageInterface)) As Boolean
        Return sizeofImpl(key, size, slices, AddressOf sizeofInfo.createInfo)
    End Function

    Protected Overrides Function keycountwork(ByVal slice As storageInterface, ByRef count As UInt64) As Boolean
        Return c(slice).tsKeyCount(count)
    End Function
End Class
